  public function executeBatch(sfWebRequest $request)
  {
    $request->checkCSRFProtection();

    if (!$ids = $request->getParameter('ids'))
    {
      $this->getUser()->setFlash('error', 'You must at least select one item.');

      $this->redirect('@<?php echo $this->getUrlForAction('list') ?>');
    }

    if (!$action = $request->getParameter('batch_action'))
    {
      $this->getUser()->setFlash('error', 'You must select an action to execute on the selected items.');

      $this->redirect('@<?php echo $this->getUrlForAction('list') ?>');
    }

    if (!method_exists($this, $method = 'execute'.ucfirst($action)))
    {
      throw new InvalidArgumentException(sprintf('You must create a "%s" method for action "%s"', $method, $action));
    }

    if (!$this->getUser()->hasCredential($this->configuration->getCredentials($action)))
    {
      $this->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
    }

    $validator = new sfValidatorPropelChoiceMany(array('model' => '<?php echo $this->getModelClass() ?>'));
    try
    {
      // validate ids
      $ids = $validator->clean($ids);

      // execute batch
      $this->$method($request);
    }
    catch (sfValidatorError $e)
    {
      $this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items as some items do not exist anymore.');
    }

    $this->redirect('@<?php echo $this->getUrlForAction('list') ?>');
  }

  protected function executeBatchDelete(sfWebRequest $request)
  {
    $ids = $request->getParameter('ids');

    $executed = array();
    $not_executed = array();
    foreach (<?php echo constant($this->getModelClass().'::PEER') ?>::retrieveByPks($ids) as $object)
    {
      $this->dispatcher->notify(new sfEvent($this, 'admin.delete_object', array('object' => $object)));

      $object->delete();
      if ($object->isDeleted())
      {
        $executed[] = strval($object);
      }
      else
      {
        $not_executed[] = strval($object);
      }
    }

    if (empty($not_executed))
    {
      $this->getUser()->setFlash('notice', 'The selected items have been deleted successfully.');
    }
    else
    {
      $this->getUser()->setFlash('batch_not_executed', $not_executed);
      $this->getUser()->setFlash('error', 'A problem occurs when deleting the selected items.');
    }

    if (!empty($executed))
      $this->getUser()->setFlash('batch_executed', $executed);

    $this->redirect('@<?php echo $this->getUrlForAction('list') ?>');
  }

<?php if ($this->configuration->hasCart()): ?>
  protected function executeBatchAddToCart(sfWebRequest $request)
  {
    $ids = $request->getParameter('ids');
    $ids = is_array($ids)? $ids : array($ids);

    $items_in_cart = $this->configuration->getCartItems();
    $items_in_cart = array_merge($items_in_cart, $ids);
    $items_in_cart = array_unique($items_in_cart);
    $this->configuration->setCartItems($items_in_cart);
    $this->getUser()->setFlash('notice', 'Items added successfully to cart.');
  }

  public function executeBatchDeleteFromCart(sfWebRequest $request)
  {
    $ids = $request->getParameter('ids', array());
    $ids = is_array($ids)? $ids : array($ids);

    $items_in_cart = $this->configuration->getCartItems();
    $items_in_cart = array_diff($items_in_cart, $ids);
    $this->configuration->setCartItems($items_in_cart);

    $this->getUser()->setFlash('notice', 'Items removed successfully from the cart.');
    $this->redirect(sfContext::getInstance()->getModuleName().'/cartIndex');
  }
<?php endif ?>
